﻿<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/Uploadify/swfobject.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/Uploadify/jquery.uploadify.v2.1.0.min.js")"></script>
<script type="text/javascript">
    var uploadFolder = "/UpFiles/Photos/";
    $(function () {

        $('#submit').click(function() {
            var imgPath = $("#ImgPath").val();
            var thumbnailPath = $("#ThumbnailPath").val();
            if (imgPath == "" || thumbnailPath == "") {
                $("#dialog").dialog({
                    modal: true
                });
                return false;
            }

        });
        //上传
        $('#fileInput1').uploadify({
            'uploader': '@Url.Content("~/Scripts/Uploadify/uploadify.swf")',
            'script': '@Url.Content("~/HomePage/Upload")',
            'folder': uploadFolder,
            'cancelImg': '@Url.Content("~/Scripts/Uploadify/cancel.png")',
            'fileExt': '*.jpg;*.gif',
            'fileDesc': 'Image Files (.JPG, .GIF)',
            'sizeLimit': 1024 * 1024 * 4, //4M
            'multi': false,
            'onComplete': fun
        });

        $("a[rel^='prettyPhoto']").prettyPhoto({ theme: 'facebook',
            opacity: 0.9,
            show_title: true,
            social_tools: false
        });

        $("#btnDelete").click(function () {

            return confirm("确定要删除该图片吗？");

        });

    });
    function fun(event, queueID, fileObj, response, data) {
        if (response != "") {
            $("#ImgPath").val(uploadFolder + response);
            $("#ThumbnailPath").val(uploadFolder + "Thumbnail/" + response);
            $("#previewLink").attr("title", $("#Title").val()).attr("href", uploadFolder + response);
            $("#previewImage").attr("alt", $("#news-content").val()).attr("src", uploadFolder + "Thumbnail/" + response);
            showInfo("成功上传" + response, true); //showInfo方法设置上传结果     
        }
        else {
            showInfo("文件上传出错！", false);
        }
    }
    //显示提示信息，textstyle2为绿色，即正确信息；textstyl1为红色，即错误信息
    function showInfo(msg, type) {
        var msgClass = type == true ? "textstyle2" : "textstyle1";
        $("#result").removeClass();
        $("#result").addClass(msgClass);
        $("#result").html(msg);
    }
    //如果点击‘导入文件’时选择文件为空，则提示
    function checkImport() {
        if ($.trim($('#fileInput1Queue').html()) == "") {
            $("<div title=\"提示\"><p><b>请先选择要上传的图片!</b></p></div>").dialog({
                modal: true
            }); ;
            return false;
        }
        return true;
    }


</script>